package lambda.lambda_ideas.before_lambda;

import lambda.lambda_ideas.base.Apple;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 苹果筛选器
 *
 * @author code-worker
 * @date 2021/10/03 10:32
 */
public class AppleFilters {

    /**
     * task: 筛选绿苹果
     * @author code-worker
     * @date 2021/10/3 10:35
     * @param inventory 苹果集合
     * @return java.util.List<lambda.lambda_ideas.base.Apple>
     */
    public static List<Apple> filerGreenApples(List<Apple> inventory){
        List<Apple> result = new ArrayList<>();
        for (Apple apple : inventory) {
            if("green".equals(apple.getColor())){
                result.add(apple);
            }
        }
        return result;
    }

    /**
     * task: 筛选大苹果
     * @author code-worker
     * @date 2021/10/3 10:35
     * @param inventory 苹果集合
     * @return java.util.List<lambda.lambda_ideas.base.Apple>
     */
    public static List<Apple> filerHeavyApples(List<Apple> inventory){
        List<Apple> result = new ArrayList<>();
        for (Apple apple : inventory) {
            if(apple.getWeight() > 150){
                result.add(apple);
            }
        }
        return result;
    }

    public static void main(String[] args) {
        List<Apple> apples = Apple.initData();
        System.out.println("green apple: "+filerGreenApples(apples));
        System.out.println("heavy apple: "+filerHeavyApples(apples));
    }

}
